<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
</head>

<body>
    <div id="info"></div>
    <script src="./jquery.js"></script>
    <script src="./template-web.js"></script>
    <script type="text/html" id="user-tpl">
        <ul>
            <li>{{name}}</li>
            <li>{{age}}</li>
            <li>{{birthday | date }}</li>
            {{if gender===1}}
            <li>男</li>
            {{else if gender===0}}
            <li>女</li>
            {{else}}
            <li>不确定</li>
            {{/if}}
            <!-- <li>{{score}}</li> -->
            <li>{{@score}}</li>
            <!-- @会解析其内容 -->
            {{each hobby}}
            <li>{{$index}};{{$value}}</li>
            {{/each}}
        </ul>
    </script>
    <script>
        $(function() {
            var userInfo = {
                name: "ww",
                age: 22,
                gender: 1,
                score: "<h4>100</h4>",
                hobby: ["吃饭", "睡觉", "打豆豆"],
                birthday: new Date()
            };
            template.defaults.imports.date = function(date) {
                var year = date.getFullYear();
                var month = date.getMonth() + 1;
                var day = date.getDate();
                return year + "-" + month + "-" + day;
            };
            var ret = template("user-tpl", userInfo);
            $("#info").html(ret);
        });
    </script>
</body>

</html>